package com.zkthink.ceres.applet.order.controller;

import cn.hutool.extra.servlet.ServletUtil;
import com.zkthink.base.R;
import com.zkthink.ceres.applet.common.domin.PageDate;
import com.zkthink.ceres.applet.order.domain.vo.*;
import com.zkthink.ceres.applet.order.service.AppletProductOrderService;
import com.zkthink.ceres.applet.order.service.AppletServerOrderService;
import com.zkthink.context.BaseContextHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author cmz
 * @Date 2024-04-30 10:31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/applet/productOrder")
@Api(value = "appletOrder", tags = "小程序订单")
public class AppletProductOrderController {
    @Resource
    private AppletProductOrderService appletProductOrderService;

    @Resource
    private AppletServerOrderService appletServerOrderService;
    
    /**
     * 是否是第一次产品下单
     * @return
     */
    @ApiOperation(value = "是否是第一次产品下单", notes = "是否是第一次产品下单")
    @GetMapping(value = "/isFirstProductOrder")
    public R isFirstProductOrder() {
        return appletProductOrderService.isFirstProductOrder();
    }

//    /**
//     * 服务下单，将订单信息初始化
//     * @param placeProductOrderVol
//     * @return
//     */
    /*@ApiOperation(value = "产品下单", notes = "产品下单")
    @PostMapping(value = "/placeProductOrder")
    public R placeProductOrder(@RequestBody PlaceProductOrderVo placeProductOrderVol) {
        return appletProductOrderService.placeServerOrder(placeProductOrderVol);
    }*/

//    /**
//     * 设置配送方式
//     * @param setDeliveryMethod
//     * @return
//     */
//    @ApiOperation(value = "设置配送方式", notes = "设置配送方式")
//    @PostMapping(value = "/setDeliveryMethod")
//    public R setDeliveryMethod(@RequestBody SetDeliveryMethod setDeliveryMethod) {
//        if (setDeliveryMethod.getProductType().equals("产品分类")){
//            return appletProductOrderService.setDeliveryMethod(setDeliveryMethod);
//        }else if (setDeliveryMethod.getProductType().equals("服务")){
//            SetServerStoreOrVehiclesVo setServerStoreOrVehiclesVo = new SetServerStoreOrVehiclesVo();
//            setServerStoreOrVehiclesVo.setAddressId(setDeliveryMethod.getAddressId());
//            setServerStoreOrVehiclesVo.setServerChannel(setDeliveryMethod.getDeliveryMethod());
//            setServerStoreOrVehiclesVo.setServerOrderId(setDeliveryMethod.getId());
//            setServerStoreOrVehiclesVo.setStoreId(setDeliveryMethod.getStoreId());
//            setServerStoreOrVehiclesVo.setVehiclesId(setDeliveryMethod.getVehiclesId());
//
//            return appletServerOrderService.setServerStoreOrVehicles(setServerStoreOrVehiclesVo);
//        }
//        return R.fail("参数值错误");
//
//    }

    @ApiOperation("产品订单支付")
    @GetMapping("/payOrder/{orderId}")
    public R<Object> payOrder(HttpServletRequest request, @PathVariable("orderId") Long orderId) {
        Long mid = BaseContextHandler.getUserId();
        return appletProductOrderService.payOrder(mid, orderId, ServletUtil.getClientIP(request));
    }

    @ApiOperation("确认收货/核销后")
    @GetMapping("/confirmReceipt/{orderId}")
    public R confirmReceipt(@PathVariable("orderId") Long orderId) {
        return appletProductOrderService.confirmReceipt(orderId);
    }

    @ApiOperation("取消支付")
    @PostMapping("/cancelPay")
    public R cancelPay(@RequestBody OrderStatusVo orderStatusVo) {
        return appletProductOrderService.cancelPay(orderStatusVo);
    }

    @ApiOperation("查询服务、产品订单列表")
    @PostMapping("/findProductOrderList")
    public R findProductOrderList(@RequestBody PageByOrderTypeVo pageByOrderTypeVo) {
        return appletProductOrderService.findProductOrderList(pageByOrderTypeVo);
    }

    @ApiOperation("刷新订单核销码")
    @GetMapping("/refreshOrderCodeUrl/{orderCode}")
    public R refreshOrderCodeUrl(@PathVariable String orderCode) {
        return appletProductOrderService.refreshOrderCodeUrl(orderCode);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/findOrderDetail/{orderCode}")
    public R<OrderDetailVo> findOrderDetail(@PathVariable String orderCode) {
        return appletProductOrderService.findOrderDetail(orderCode);
    }

    @ApiOperation("服务订单测评信息填写")
    @PostMapping("/serverOrderAssess")
    public R serverOrderAssess(@RequestBody ServerOrderAssessVo serverOrderAssessVo) {
        return appletProductOrderService.serverOrderAssess(serverOrderAssessVo);
    }


    @ApiOperation("查询测评记录")
    @PostMapping("/selectAssess")
    public R selectAssess(@RequestBody PageDate pageDate) {
        return appletProductOrderService.selectAssess(pageDate);
    }
    
    
    
}
